package jokode

import "strings"

type LogLevel int

const (
	LogLevelDebug LogLevel = iota
	LogLevelInfo
	LogLevelWarn
	LogLevelError
	LogLevelFatal

	LogLevelUnknown = 100
)

const (
	LogLevelStrDebug = "DEBUG"
	LogLevelStrInfo  = "INFO"
	LogLevelStrWarn  = "WARN"
	LogLevelStrError = "ERROR"
	LogLevelStrFatal = "FATAL"

	LogLevelStrUnknown = "UNKNOWN"
)

func (level LogLevel) String() string {
	switch level {
	case LogLevelDebug:
		return LogLevelStrDebug
	case LogLevelInfo:
		return LogLevelStrInfo
	case LogLevelWarn:
		return LogLevelStrWarn
	case LogLevelError:
		return LogLevelStrError
	case LogLevelFatal:
		return LogLevelStrFatal
	default:
		return LogLevelStrUnknown
	}
}

func ParseLogLevel(str string) LogLevel {
	upper := strings.ToUpper(str)
	switch upper {
	case LogLevelStrDebug:
		return LogLevelDebug
	case LogLevelStrInfo:
		return LogLevelInfo
	case LogLevelStrWarn:
		return LogLevelWarn
	case LogLevelStrError:
		return LogLevelError
	case LogLevelStrFatal:
		return LogLevelFatal
	default:
		return LogLevelUnknown
	}
}
